package com.gaoy.springdemo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("user2")
@RestController
public class UserController2 {
    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session) {
        //暂时写死密码和账号;
//        if(username==null&&password==null) {
//            return false;
//        }
        if (!StringUtils.hasLength(username)||!StringUtils.hasLength(password)){
            return false;
        }
        //校验用户名和密码是否正确
        if ("admin".equals(username)&&"123456".equals(password)){
            session.setAttribute("username",username);
            return true;
        }
        return false;
    }
    @RequestMapping("/getLoginUser")
    public  String getLoginUser(HttpSession session){
        String username = (String) session.getAttribute("username");
        return username;
    }
}

